package org.lysh.response;

import org.lysh.enums.BusinessCode;

import java.io.Serializable;

/**
 * @author liyishan
 * @date 2024/4/24 15:30
 * @apiNote
 */

public class BlogResponse<T> implements Serializable {
    private String statusCode = "000000";
    private String statusText = "success";
    private T data;

    public BlogResponse() {
        this.statusCode = BusinessCode.SUCCESS.getCode();
        this.statusText = "success";
        this.data = null;
    }

    public BlogResponse(String statusCode, String statusText, T t, String currentTimeMillis) {
        this.statusCode = statusCode;
        this.statusText = statusText;
        this.data = t;
    }

    public BlogResponse(String statusCode, String statusText) {
        this.statusCode = statusCode;
        this.statusText = statusText;
        this.data = null;
    }

    public BlogResponse(String statusCode, String statusText, T t) {
        this.statusCode = statusCode;
        this.statusText = statusText;
        this.data = t;
    }

    public BlogResponse(BusinessCode businessCode) {
        this.statusCode = businessCode.getCode();
        this.statusText = businessCode.getDesc();
        this.data = null;
    }

    public BlogResponse(BusinessCode businessCode, T data) {
        this.statusCode = businessCode.getCode();
        this.statusText = businessCode.getDesc();
        this.data = data;
    }

    public static BlogResponse Success() {
        return new BlogResponse(BusinessCode.SUCCESS);
    }

    public static BlogResponse Success(Object data) {
        return new BlogResponse(BusinessCode.SUCCESS, data);
    }

    public static BlogResponse Error() {
        return new BlogResponse(BusinessCode.FATAL);
    }

    public static BlogResponse Error(String errMsg) {
        return new BlogResponse(BusinessCode.FATAL.getCode(), errMsg);
    }

    public static BlogResponse Warn(String errMsg) {
        return new BlogResponse(BusinessCode.WARN.getCode(), errMsg);
    }

    public static BlogResponse Error(BusinessCode businessCode, String errMsg) {
        return new BlogResponse(businessCode.getCode(), errMsg);
    }

    public boolean successful() {
        return this.statusCode.equals(BusinessCode.SUCCESS.getCode());
    }

    public String getStatusCode() {
        return this.statusCode;
    }

    public String getStatusText() {
        return this.statusText;
    }

    public T getData() {
        return this.data;
    }

    public void setStatusCode(String statusCode) {
        this.statusCode = statusCode;
    }

    public void setStatusText(String statusText) {
        this.statusText = statusText;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String toString() {
        return "HygResponse(statusCode=" + this.getStatusCode() + ", statusText=" + this.getStatusText() + ", data=" + this.getData() + ")";
    }
}
